//
//  IPMeController.swift
//  IPlan
//
//  Created by robot on 3/19/16.
//  Copyright © 2016 codeFighter.com. All rights reserved.
//

import UIKit
import SnapKit
class IPMeController: UIViewController {

    lazy var meTableView = UITableView()
    var meTableTitles = ["宣言:不能坚持，就别开始","计划完成度","分享爱计划","清除缓存","意见反馈","检测新版本","去评分"]
    
    override func viewDidLoad() {
        
        super.viewDidLoad()
        navigationItem.title = "我的"
        view.backgroundColor = UIColor.init(netHex: 0xF1F1F1)
        view.autoresizesSubviews = false
        // Do any additional setup after loading the view.
        setUpTableView()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
    }
    
    func setUpTableView (){
    
        meTableView.dataSource = self
        meTableView.delegate = self
        view.addSubview(meTableView)
        meTableView.backgroundColor = UIColor.white
        meTableView.snp.makeConstraints { (make) in
            
            make.top.equalTo(view.snp.top).offset(0)
            make.bottom.equalTo(view.snp.bottom)
            make.left.equalTo(0)
            make.right.equalTo(0);
            
        }
        
        let headView = Bundle.main.loadNibNamed("IPMeHeadView", owner: nil, options: nil)?.last
            as! IPMeHeadView

        meTableView.tableHeaderView = headView
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension IPMeController: UITableViewDataSource,UITableViewDelegate{
    
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 54
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return meTableTitles.count
    }

    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 10.0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        var meTableViewCell = tableView.dequeueReusableCell(withIdentifier: "meCell")
        if meTableViewCell == nil{
        
        meTableViewCell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier:"meCell")
        }
        meTableViewCell?.textLabel?.font = UIFont.systemFont(ofSize: 14.0)
        meTableViewCell?.textLabel?.text = meTableTitles[(indexPath as NSIndexPath).row]
        meTableViewCell?.selectionStyle = .none
        return meTableViewCell!
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        
        let headView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: SCREEN_W, height: 10))
        headView.backgroundColor = UIColor.init(netHex: 0xF1F1F1)
        return headView
    }
    
}

